Conversation
s3rius
left a comment
There was a problem hiding this comment.
I like the new implementation. We need to not forget to bump major version so people won't get this update by accident. Also I highlighted few places. Which could be updated, but it's not something critical.
| class AioKafkaKicker(AsyncKicker[_FuncParams, _ReturnType]): | ||
| """Kicker that can override kafka topic for a task call.""" | ||
|
|
||
| def with_topic( |
There was a problem hiding this comment.
The problem with this method is that broker doesn't carry information about the decorator_class field.
Although it will definitely work, but pyright will never suggest you this method, and mypy will always be complaining about using it.
I think this particular issue worth thinking through more carefully. I guess extending kicker functionality for different brokers is one of those things that could actually be helpful for lots of places, but current implementation is a total lame fr. Maybe we could update this type information internally somehow without affecting other brokers allowing users and lib devs to extend kicker functionality while getting all they type-hinting benefits.
update: task_with_topic interface update: tests
20fbd5e to
32d4dc5
Compare
Summary
Adds multi-topic support to
AioKafkaBrokerwhile keeping the existing single-topic behavior fully backward compatible.Why
Some projects need different task groups to use different Kafka topics, while still running through the same taskiq broker and worker setup. For example, regular tasks, email tasks, reports, or priority-specific workloads may need separate Kafka topics for routing, isolation, monitoring, or operational control.
Previously,
AioKafkaBrokeralways sent every task to one broker-level Kafka topic. This change allows each task to define its own default topic, and also allows overriding the topic for a singlekiqcall.What Changed
TopicConfigandTopichelper structures.AioKafkaBrokerwith multi-topic support:kafka_topicremains the default topic.kafka_topicscan be used to configure additional topics for the worker to listen to.@broker.task(topic="...")sets a default Kafka topic for that task.task.kicker().with_topic("...").kiq(...)overrides the topic for a single task kick.delete_topic_on_shutdown=True.AioKafkaBrokerusage.